package com.zhiyou.controller;

import java.sql.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhiyou.service.DormManageService;
import com.zhiyou.utils.JsonResult;

@RestController
@RequestMapping("dorm/")
public class DormManageController {

	@Autowired
	DormManageService dormManageService;
	
	//主页展示
	@GetMapping("dormShow/{DormCurrentDate}/{id}")
	public JsonResult show(@PathVariable("DormCurrentDate")Date date,@PathVariable("id") Integer id,HttpServletRequest request,HttpServletResponse response){
		System.out.println("时间为:"+date+"id是"+id+"**********************************************");	
		return new JsonResult(dormManageService.SelectJuDge(date, id),"查询成功");
	}
	
	//详情
	@GetMapping("xq/{ids}/{buildingId}/{DormCurrentDate}/{DormId}")
	public JsonResult xiangqing(@PathVariable("ids")Integer ids,@PathVariable("buildingId")Integer building_id,@PathVariable("DormCurrentDate")Date date,@PathVariable("DormId")Integer dorm_id 
	,HttpServletRequest request,HttpServletResponse response){
		System.out.println(dormManageService.SelectByBuildingDetails(ids, building_id, date, dorm_id));
		return new JsonResult(dormManageService.SelectByBuildingDetails(ids, building_id, date, dorm_id),"查询成功");
	}
	
	
	//模糊查询
	@GetMapping("mohu/{student_name}")
	public JsonResult mohu(@PathVariable("student_name")String student_name,HttpServletRequest request,HttpServletResponse response){
	System.out.println(dormManageService.selectByStudentName(student_name)+"*****************************************");
	return new JsonResult(dormManageService.selectByStudentName(student_name),"查询成功");
	} 
	
	@GetMapping("xiu/{student_id}/{dorm_current_date}")
	public JsonResult xiugai(@PathVariable("student_id")Integer student_id,@PathVariable("dorm_current_date") Date dorm_current_date){
		System.out.println("学生ID为:"+student_id+";时间为:"+dorm_current_date+"*****************************************");
		return new JsonResult(dormManageService.SDormA(student_id, dorm_current_date),"修改成功");		
	}
	
	
	
}
